package org.huawei260.TiKu.ODsuanfa;

/**
 * @Author: qingle
 * @Date: 2024/10/28-16:11
 * @Description: 3108 【DP_贪心】2024E-贪心的商人
 * @version: 1.0
 */
import java.util.Scanner;
public class E_2024E_3108__DP_贪心_贪心的商人 {

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			int number = sc.nextInt();
			int days = sc.nextInt();

			int[] maxCount = new int[number];
			for (int i = 0; i < number; i++) {
				maxCount[i] = sc.nextInt();
			}

			int[][] prices = new int[number][days];
			for (int i = 0; i < number; i++) {
				for (int j = 0; j < days; j++) {
					prices[i][j] = sc.nextInt();
				}
				// System.out.println(0); // 如果通过率未达100%，可以尝试解开这行注释，应该会有所提升
			}

			System.out.println(getResult(number, days, maxCount, prices));
		}

		/**
		 * @param number 几种商品
		 * @param days 几天
		 * @param maxCount 每种商品的最大囤货数量
		 * @param prices 每种商品的在days天内的价格变动情况
		 * @return 最大利润
		 */
		public static int getResult(int number, int days, int[] maxCount, int[][] prices) {
			int ans = 0;
			for (int i = 0; i < number; i++) {
				int[] price = prices[i];
				for (int j = 0; j < days - 1; j++) {
					if (price[j] < price[j + 1]) {
						ans += (price[j + 1] - price[j]) * maxCount[i];
					}
				}
			}
			return ans;
		}
	}
